import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import '../models/counter_model.dart';
import 'settings_page.dart';
class HomePage extends StatelessWidget{
  const HomePage ({super.key});

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text('Provider Demo'),
        actions: [
          IconButton(onPressed: ()=>Navigator.push(
            context,MaterialPageRoute(builder: (_)=>const SettingsPage())
          ),
              icon: Icon(Icons.settings)),
        ],
      ),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: [
            const Text('Current Count:'),
            Consumer<CounterModel>(//Consumer（推荐局部刷新）
              builder: (context,model,child)=>Text(
                '${model.count}',style: Theme.of(context).textTheme.displayLarge,
              ),
            )
          ],
        ),
      ),//context.read（在事件回调中）//context.read（在事件回调中）
      floatingActionButton: FloatingActionButton(
        onPressed: ()=>context.read<CounterModel>().increment(),
        child: const Icon(Icons.add),
      ),
    );
  }
  
}